<style lang="less">
  @import './login.less';
</style>

<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit" ref="login"></login-form>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from '_c/login-form'
import URL from '@/api/login'
import axios from 'axios'
import md5 from 'md5'
export default {
  name: 'login',
  components: {
    LoginForm
  },
  methods: {
    async handleSubmit ({ userName, password, captcha }) {
      let mPassword = md5(password)
      let oData = await axios.post(URL.login, {
        userName,
        password: mPassword,
        captcha
      }).then(res => {
        return res.data
      })
      if (oData.code === 0) {
        this.$Message.success(oData.message)
        this.$router.push({ name: 'user_list' })
      } else {
        this.$refs.login.getCodeImg()
        this.$Message.error(oData.message)
      }
    }
  }
}
</script>
